// ts 增强了class类

export {};

interface Option {
  name: string;
}

class Person {
  public age: number = 18; // 公开属性
  private name: string = "张三"; //私有属性
  protected sex: string = "name"; //可以被子类访问
  constructor(option: Option) {
    this.name = option.name;
  }
  getName() {
    return this.name;
  }
  setName(name: string) {
    this.name = name;
  }
}

let person = new Person({
  name: "李四",
});

class Student extends Person {
  static student: Student;
  private constructor(option: Option) {
    super(option);
    console.log(this.sex);
  }
  // 懒汉模式 单例模式
  static create(option: Option) {
    if (Student.student) {
      return Student.student;
    } else {
      return (Student.student = new Student(option));
    }
  }
}

let student = Student.create({
  name: "王五",
});
let student1 = Student.create({
  name: "赵六",
});
console.log(person.age);
console.log(student.getName());
console.log(student1.getName());
console.log(student === student1);
